﻿package mortal.game.view.guildNew.activity
{
    import Message.Client.*;
    import Message.DB.Tables.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.daily.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.mvc.core.*;

    public class GuildNewActiveCell extends GCellRenderer
    {
        protected var _itemBg:GBitmap;
        protected var _pic:GImageBitmap;
        protected var _line:ScaleBitmap;
        protected var _nameBg:GBitmap;
        protected var _list:CellsGridSprite;
        protected var _timeDes:GTextFiled;
        protected var _time2:GTextFiled;
        protected var _con1:GTextFiled;
        protected var _con2:GTextFiled;
        protected var _optn:GButton;
        protected var _findWay:GButton;
        protected var _flyShoe:GLoadedButton;
        protected var _goBtn:GButton;
        protected var _rewardIcon:GBitmap;
        private var _starPanel:StarPanel;
        private var _nameOBj:Object;

        public function GuildNewActiveCell()
        {
            this._nameOBj = {8:"GuildNActive3", 18:"GuildNActive0", 14:"GuildNActive6", 11:"GuildNActive5"};
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._itemBg = UIFactory.gBitmap(ImagesConst.GuildNActiveIconBg, 8, 4, this);
            this._pic = UIFactory.gImageBitmap("daily_guild_war.jpg", 12, 8, this);
            this._line = UIFactory.bg(-3, 74, 690, 2, this, ImagesConst.SplitLine);
            this._nameBg = UIFactory.gBitmap(ImagesConst.GuildNActive0, 84, 28, this);
            this._timeDes = UIFactory.gTextField("", 395, 7, 200, 20, this, GlobalStyle.textFormatHuang2.setSize(13).center().setBold(true));
            this._time2 = UIFactory.gTextField("", 431, 40, 120, 25, this, GlobalStyle.textFormatLv.setSize(13).center());
            this._con1 = UIFactory.gTextField("" + Language.getString(71411), 588, 19, 110, 25, this, GlobalStyle.textFormatHong.setSize(13).center());
            this._con2 = UIFactory.gTextField("" + Language.getString(71412), 595, 41, 100, 25, this, GlobalStyle.textFormatHong.setSize(13));
            this._optn = UIFactory.gButton("" + Language.getString(71413), 608, 29, 70, 26, this);
            this._findWay = UIFactory.gButton("" + Language.getString(71414), 608, 27, 50, 30, this, "GreenLinkButton");
            this._flyShoe = UIFactory.gLoadedButton(ImagesConst.MapBtnFlyBoot_upSkin, 649, 34, 16, 18, this);
            this._flyShoe.label = "";
            this._rewardIcon = UIFactory.gBitmap(ImagesConst["GuildNActiveRw0"], 266, 30, this);
            this._flyShoe.configEventListener(MouseEvent.CLICK, this.onClickBtnFlyBoot);
            this._starPanel = UIFactory.getUICompoment(StarPanel, 301, 25, this);
            this._starPanel.setStarStyle(ImagesConst.GuildWarStarM, ImagesConst.GuildWarStarMGray, 25);
            var _loc_1:Boolean = false;
            this._con2.visible = false;
            this._con1.visible = _loc_1;
            this._optn.configEventListener(MouseEvent.CLICK, this.onClickOperBtn);
            this._findWay.configEventListener(MouseEvent.CLICK, this.onClickOperBtn);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._itemBg = null;
            this._pic = null;
            this._line = null;
            this._nameBg = null;
            this._timeDes = null;
            this._time2 = null;
            this._con1 = null;
            this._con2 = null;
            this._optn = null;
            this._findWay = null;
            this._flyShoe = null;
            this._rewardIcon = null;
            this._starPanel = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function get itemData() : TDailyViewConfig
        {
            return data as TDailyViewConfig;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._pic.imgUrl = this.itemData.icon + ".jpg";
            this._flyShoe.visible = false;
            this._nameBg.bitmapData = GlobalClass.getBitmapData(this.getBg());
            this._time2.htmlText = Language.getStringByParam(70484, this.itemData.minLevel);
            this.setBtnLabel();
            this.setPlanTxt();
            this.setStar();
            return;
        }// end function

        private function getBg() : String
        {
            if (data.hasOwnProperty("guildActiveName"))
            {
                return data["guildActiveName"];
            }
            return "GuildNActive0";
        }// end function

        private function onClickOperBtn(event:MouseEvent) : void
        {
            if (this.itemData.type == 33)
            {
                Dispatcher.dispatchEvent(new DataEvent(GuildNewLocalEvent.ModuleChangeTab, "m4"));
            }
            else
            {
                DailyUtil.oper(this.itemData);
            }
            return;
        }// end function

        private function onClickBtnFlyBoot(event:MouseEvent) : void
        {
            DailyUtil.oper(this.itemData, true);
            return;
        }// end function

        private function setPlanTxt() : void
        {
            var _loc_2:String = null;
            var _loc_3:String = null;
            var _loc_4:Array = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_1:* = Cache.instance.daily;
            this._timeDes.textColor = GlobalStyle.colorLvUint;
            if (int(this.itemData.times) > 0)
            {
                if (int(_loc_1.data.times[this.itemData.type]) >= int(this.itemData.activityValue))
                {
                    this._timeDes.textColor = GlobalStyle.colorHuang2Uint;
                    this._timeDes.text = int(this.itemData.activityValue) + "/" + this.itemData.activityValue;
                }
                else
                {
                    this._timeDes.text = int(_loc_1.data.times[this.itemData.type]) + "/" + this.itemData.activityValue;
                }
            }
            else if (this.itemData.normalOpenDt)
            {
                _loc_2 = DailyUtil.getTimeStr(this.itemData.normalOpenDt);
                if (this.itemData.openWeekDay)
                {
                    _loc_3 = "";
                    _loc_4 = this.itemData.openWeekDay.split("#");
                    _loc_5 = _loc_4.length;
                    _loc_6 = 0;
                    while (_loc_6 < _loc_5)
                    {
                        
                        _loc_3 = _loc_3 + GameDefConfig.instance.getChineseNum(int(_loc_4[_loc_6]));
                        _loc_6++;
                    }
                    this._timeDes.text = Language.getStringByParam(70407, _loc_3 + _loc_2);
                }
                else
                {
                    this._timeDes.text = Language.getStringByParam(70408, _loc_2);
                }
            }
            else
            {
                this._timeDes.text = "" + Language.getString(71415);
            }
            return;
        }// end function

        private function setStar() : void
        {
            if (this.itemData.expStar > 0)
            {
                this._rewardIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildNActiveRw1);
                this._starPanel.setStarNum(this.itemData.expStar, this.itemData.expStar);
            }
            else if (this.itemData.coinStar > 0)
            {
                this._rewardIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildNActiveRw2);
                this._starPanel.setStarNum(this.itemData.coinStar, this.itemData.coinStar);
            }
            else if (this.itemData.itemStar > 0)
            {
                this._rewardIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildNActiveRw0);
                this._starPanel.setStarNum(this.itemData.itemStar, this.itemData.itemStar);
            }
            return;
        }// end function

        private function setBtnLabel() : void
        {
            if (this.itemData.operType == EDailyOperType._EDailyOperTypeModule)
            {
                this._optn.visible = true;
                var _loc_1:Boolean = false;
                this._flyShoe.visible = false;
                this._findWay.visible = _loc_1;
            }
            else if (this.itemData.operType == EDailyOperType._EDailyOperTypePathing)
            {
                this._optn.visible = false;
                var _loc_1:Boolean = true;
                this._flyShoe.visible = true;
                this._findWay.visible = _loc_1;
            }
            return;
        }// end function

    }
}
